﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Cfg;
using ZSedu.Manager;
using ZSedu.Model;
namespace ZSedu
{
    class Program
    {
        static void Main(string[] args)
        {
            #region  nhibernate 直接操作数据库
            ////配置
            //var configration = new Configuration();
            ////解析nhibernate.cfg.xml
            //configration.Configure();
            ////添加程序 解析映射文件
            //configration.AddAssembly("ZSedu");

            ////生产工厂
            //ISessionFactory sessionFactory=null;
            //ISession session=null;
            //ITransaction transaction=null;
            //try
            //{
            //    sessionFactory = configration.BuildSessionFactory();
            //   //打开一个数据库的会话
            //     session=  sessionFactory.OpenSession();
            //    //User user = new User() { Username = "dslfkjer", Password = "4545" };
            //    //session.Save(user);

            //    //事务
            //    transaction = session.BeginTransaction();
            //    User user1 = new User() { Username = "zsssss", Password = "7897988" };
            //    User user2 = new User() { Username = "zsssss", Password = "7897988" };
            //    session.Save(user1);
            //    session.Save(user2);
            //    transaction.Commit();
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}
            //finally 
            //{
            //    if (transaction!=null) 
            //    {
            //        transaction.Dispose();
            //    }

            //    if (session != null)
            //    {
            //        session.Close();
            //    }
            //    if (sessionFactory!=null) 
            //    {
            //        sessionFactory.Close();
            //    }
            //}
            #endregion

            #region 测试NHibernate
            //User user = new User() { Username = "瞎搞", Password = "4545" };
            //UserManager userManager = new UserManager();
            //userManager.Add(user);
            #endregion

            
            Console.ReadKey();

        }
    }
}
